package game.spider.peri;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.Rect;
import android.graphics.drawable.BitmapDrawable;
import android.util.Log;
import android.view.MotionEvent;
import net.ds0101.framework.android.neox.core.NXEventHandler;
import net.ds0101.framework.android.neox.core.NXMenuItemActionHandler;
import net.ds0101.framework.android.neox.core.NXNode;
import net.ds0101.framework.android.neox.main.NXDirector;
import net.ds0101.framework.android.neox.main.NXScene;
import net.ds0101.framework.android.neox.widget.NXMenu;
import net.ds0101.framework.android.neox.widget.NXMenuItemImage;
import net.ds0101.framework.android.neox.widget.NXMenuItemSprite;
import net.ds0101.framework.android.neox.widget.NXSprite;

public class MainMenu extends NXScene {
	NXMenu mMenu;

	public MainMenu(Context context) {
		super(context);
	}
	
	@Override
	public void onEnter() {
		super.onEnter();
		Bitmap bmp = 
			((BitmapDrawable)getResources().getDrawable(R.drawable.menustart)).getBitmap();
		if (null != bmp) {
			NXSprite menuStart[] = new NXSprite[3];
			menuStart[0] = NXSprite.spriteWithBitmap(bmp, new Rect(0, 0, 99, 40));
			menuStart[1] = NXSprite.spriteWithBitmap(bmp, new Rect(0, 40, 99, 80));
			menuStart[2] = NXSprite.spriteWithBitmap(bmp, new Rect(0, 80, 99, 120));
			NXMenuItemSprite menuItem = 
				new NXMenuItemSprite(menuStart[0], menuStart[1], menuStart[2], null, new NXMenuItemActionHandler() {
				@Override
				public void onTapped(NXNode sender) {
					director().pushScene(new GameScene(getContext()));
				}

				@Override
				public void onPressed(NXNode sender) {
				}

				@Override
				public void onReleased(NXNode sender) {
				}
					
				});
			
			if (null != menuItem) {
				mMenu = new NXMenu(menuItem);
				mMenu.position(NXDirector.getScreenWidth() / 2, NXDirector.getScreenHeight() / 2);
				//menuItem.position(NXDirector.getScreenWidth() / 2, NXDirector.getScreenHeight() / 2);
				addChild(mMenu, 1);
			}
		}
	}

	@Override
	public void update(int arg0) {
		// TODO Auto-generated method stub

	}

	@Override
	public void onScreenSizeChanged(int newWidth, int newHeight) {
		mMenu.position(NXDirector.getScreenWidth() / 2, NXDirector.getScreenHeight() / 2);
	}

}
